import store from '@/store'
export default {
    install(Vue, options) {
        options;
        Vue.directive("authority", function (el, binding) {
            // el 操作的元素
            // binding 指令相关的属性
            console.log("el", el);
            console.log("binding", binding);

            var role = store.state.userInfo.role;
            console.log("role", role);  // 1  2  3  

            var enumRole = {
                "1": "superAdmin",
                "2": "admin",
                "3": "normal",
            }

            if (Object.hasOwn(enumRole, role)) {
                var roler = enumRole[role];
                var { arg = 'disabled', value } = binding;

                console.log(value.includes(roler));
                if (!value.includes(roler)) {  // value => 数组,可以访问的用户  roler=> 当前用户的角色
                    switch (arg) {
                        case "disabled":
                            el.disabled = true;
                            el.classList.add("is-disabled");
                            console.log(1111, el);
                            break;
                        case "remove":
                            // el.remove();
                            // el.parentElement.removeChild(el);
                            console.log(el.remove);
                            el.remove();
                            break;
                    }
                }

            } else {
                var err = new Error("用户等级范围1-3");
                throw err;
            }


        })

    }
}